import { TweenPlugin } from "./TweenPlugin";
import { HexColorsPlugin } from "./HexColorsPlugin";
import { PropTween } from "../core/PropTween";
type int = number;
//class FilterPlugin
    
    export  class FilterPlugin extends TweenPlugin
    {
       

        protected initFilter(arg1: Object, arg2: Object /* flash.filters.BitmapFilter */, arg3: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc1=this._target.filters;
            var loc5=arg1 is flash.filters.BitmapFilter ? {} : arg1;
            this._index = -1;
            if (loc5.index == null) 
            {
                loc3 = loc1.length;
                while (loc3--) 
                {
                    if (!(loc1[loc3] is this._type)) 
                    {
                        continue;
                    }
                    this._index = loc3;
                }
            }
            else 
            {
                this._index = loc5.index;
            }
            if (this._index == -1 || loc1[this._index] == null || loc5.addFilter == true) 
            {
                this._index = loc5.index == null ? loc1.length : loc5.index;
                loc1[this._index] = arg2;
                this._target.filters = loc1;
            }
            this._filter = loc1[this._index];
            if (loc5.remove == true) 
            {
                this._remove = true;
                this.onComplete = this.onCompleteTween;
            }
            loc3 = arg3.length;
            while (loc3--) 
            {
                if (!((loc2 = arg3[loc3]) in arg1 && !(this._filter[loc2] == arg1[loc2]))) 
                {
                    continue;
                }
                if (loc2 == "color" || loc2 == "highlightColor" || loc2 == "shadowColor") 
                {
                    (loc4 = new HexColorsPlugin()).initColor(this._filter, loc2, this._filter[loc2], arg1[loc2]);
                    _tweens[_tweens.length] = new PropTween(loc4, "changeFactor", 0, 1, loc2, false);
                    continue;
                }
                if (loc2 == "quality" || loc2 == "inner" || loc2 == "knockout" || loc2 == "hideObject") 
                {
                    this._filter[loc2] = arg1[loc2];
                    continue;
                }
                addTween(this._filter, loc2, this._filter[loc2], arg1[loc2], loc2);
            }
            return;
        }

        public onCompleteTween(): void
        {
            var loc1=null;
            var loc2=0;
            if (this._remove) 
            {
                loc1 = this._target.filters;
                if (loc1[this._index] is this._type) 
                {
                    loc1.splice(this._index, 1);
                }
                else 
                {
                    loc2 = loc1.length;
                    while (loc2--) 
                    {
                        if (!(loc1[loc2] is this._type)) 
                        {
                            continue;
                        }
                        loc1.splice(loc2, 1);
                        break;
                    }
                }
                this._target.filters = loc1;
            }
            return;
        }

        public /* override */ set changeFactor(arg1: number)
        {
            var loc2=null;
            var loc1=_tweens.length;
            var loc3=this._target.filters;
            while (loc1--) 
            {
                loc2 = _tweens[loc1];
                loc2.target[loc2.property] = loc2.start + loc2.change * arg1;
            }
            if (!(loc3[this._index] is this._type)) 
            {
                var loc4;
                this._index = loc4 = loc3.length;
                loc1 = loc4;
                while (loc1--) 
                {
                    if (!(loc3[loc1] is this._type)) 
                    {
                        continue;
                    }
                    this._index = loc1;
                }
            }
            loc3[this._index] = this._filter;
            this._target.filters = loc3;
            return;
        }

        public static /* const */VERSION: number=2.03;

        public static /* const */API: number=1;

        protected /* var */_target: Object;

        protected /* var */_type: Class;

        protected /* var */_filter: Object /* flash.filters.BitmapFilter */;

        protected /* var */_index: int;

        protected /* var */_remove: Boolean;
    }
